package com.afsadmedia.pregnancy;

import java.util.ArrayList;  
import android.app.Activity;  
import android.content.Context;  
import android.content.Intent;
import android.graphics.Bitmap;  
import android.os.Bundle;  
import android.util.Log;  
import android.view.LayoutInflater;  
import android.view.Menu;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.view.ViewGroup;  
import android.widget.BaseAdapter;  
import android.widget.CheckBox;  
import android.widget.ImageView;  
import android.widget.ListView;  
import android.widget.TextView;  
import android.widget.Toast;  
public class SympotomsListview extends Activity {  
     private ListView listview;  
     ArrayList<String> items = new ArrayList<String>();  
     private int count;  
     private boolean[] thumbnailsselection;  
     @Override  
     protected void onCreate(Bundle savedInstanceState) {  
          super.onCreate(savedInstanceState);  
          setContentView(R.layout.symptoms_listview);  
          fillarray();  
          count = items.size();  
          thumbnailsselection = new boolean[count];  
          listview = (ListView) findViewById(R.id.listView_symptomsselect);  
          listview.setAdapter(new ImageAdapter(SympotomsListview.this));  
     }  
     private void fillarray() {  
          // TODO Auto-generated method stub  
          items.clear();  
          items.add("Symptoms 1");  
          items.add("Symptoms 2");  
          items.add("Symptoms 3");  
          items.add("Symptoms 4");  
          items.add("Symptoms 5");  
          items.add("Symptoms 6");  
          items.add("Symptoms 7");  
          
     }  
//     @Override  
//     public boolean onCreateOptionsMenu(Menu menu) {  
//          // Inflate the menu; this adds items to the action bar if it is present.  
//          getMenuInflater().inflate(R.menu.activity_main, menu);  
//          return true;  
//     }  
     public class ImageAdapter extends BaseAdapter {  
          private LayoutInflater mInflater;  
          private Context mContext;  
          public ImageAdapter(Context context) {  
               mContext = context;  
          }  
          public int getCount() {  
               return count;  
          }  
          public Object getItem(int position) {  
               return position;  
          }  
          public long getItemId(int position) {  
               return position;  
          }  
          public View getView(int position, View convertView, ViewGroup parent) {  
               ViewHolder holder;  
               if (convertView == null) {  
                    holder = new ViewHolder();  
                    convertView = LayoutInflater.from(mContext).inflate(  
                              R.layout.listitem_sympotomselect, null);  
                    holder.textview = (TextView) convertView  
                              .findViewById(R.id.tv_symptom);  
                    holder.checkbox = (CheckBox) convertView  
                              .findViewById(R.id.checkBox_symptoms);  
                    
                    convertView.setTag(holder);  
               } else {  
                    holder = (ViewHolder) convertView.getTag();  
               }  
               holder.checkbox.setId(position);  
               holder.textview.setId(position);  
               holder.checkbox.setOnClickListener(new OnClickListener() {  
                    public void onClick(View v) {  
                         // TODO Auto-generated method stub  
                         CheckBox cb = (CheckBox) v;  
                         int id = cb.getId();  
                         if (thumbnailsselection[id]) {  
                              cb.setChecked(false);  
                              thumbnailsselection[id] = false;  
                         } else {  
                              cb.setChecked(true);  
                              thumbnailsselection[id] = true;  
                         }  
                         
                         
                       
                    }  
               });  
               holder.textview.setOnClickListener(new OnClickListener() {  
                    public void onClick(View v) {  
                         // TODO Auto-generated method stub  
                         int id = v.getId();  
                    }  
               });  
               holder.textview.setText(items.get(position));  
               holder.checkbox.setChecked(thumbnailsselection[position]);  
               holder.id = position;  
               return convertView;  
          }  
     }  
     class ViewHolder {  
          TextView textview;  
          CheckBox checkbox;  
          int id;  
     }  
     public void click(View v) {  
          if (v.getId() == R.id.button_ok_symptomlistview) {  
               final ArrayList<Integer> posSel = new ArrayList<Integer>(); 
               Constants.selectSymptoms = new ArrayList<String>(); 
               posSel.clear();  
               boolean noSelect = false;  
               for (int i = 0; i < thumbnailsselection.length; i++) {  
                    if (thumbnailsselection[i] == true) {  
                         noSelect = true;  
                         Log.e("sel pos thu-->", "" + i);  
                         String abc = items.get(i);
                         
                         Log.e("sel pos val-->", "" + abc);
                         Constants.selectSymptoms.add(abc);  
                         // break;  
                    }  
               }  
               if (!noSelect) {  
                    Toast.makeText(SympotomsListview.this, "Please Select Item!",  
                              Toast.LENGTH_SHORT).show();  
               } else {  
                    Toast.makeText(SympotomsListview.this,  
                              "Selected Items:" + Constants.selectSymptoms.toString(),  
                              Toast.LENGTH_LONG).show(); 
                    Intent i = new Intent(getApplicationContext(),Symptoms.class);
                    startActivity(i);
                   
               }
               
          }
          
          if(v.getId() == R.id.button_cancel_symptomlistview){
        	  Intent i = new Intent(getApplicationContext(),Symptoms.class);
              startActivity(i);
          }
     }  
     
 
     
     
}  
